<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      router
    >
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template #title>
              <i :class="item.icon"></i>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template #title>{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                  >{{ threeItem.title }}</el-menu-item
                >
              </el-submenu>
              <el-menu-item
                v-else
                :index="subItem.index"
                :key="subItem.index"
                >{{ subItem.title }}</el-menu-item
              >
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <template #title>
              <span>{{ item.title }}</span>
            </template>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: [
        {
          icon: "bi bi-house-door",
          index: "/admin/dashboard",
          title: "系统首页",
        },
        {
          icon: "bi bi-person",
          index: "1",
          title: "用户管理",
          subs: [
            {
              index: "/admin/userList",
              title: "用户信息",
            },
          ],
        },
        {
          icon: "bi bi-card-text",
          index: "2",
          title: "留言管理",
          subs: [
            {
              index: "/admin/messageList",
              title: "留言信息",
            },
          ],
        },
        {
          icon: "bi bi-gear",
          index: "3",
          title: "权限管理",
          subs: [
            {
              index: "/admin/roles",
              title: "角色展示",
            },
          ],
        },
        {
          icon: "bi bi-cursor",
          index: "4",
          title: "home页面",
          subs: [
            {
              index: "/admin/homeCardInfo",
              title: "校园名人榜",
            },
            {
              index: "/admin/homeNotice",
              title: "校园公告栏",
            },
          ],
        },
        {
          icon: "bi bi-question-diamond",
          index: "5",
          title: "党史页面",
          subs: [
            {
              index: "/admin/partyHistoryTimeLine",
              title: "党的奋斗史",
            },
            {
              index: "/admin/partyHistoryLeaders",
              title: "领导人展示",
            },
            {
              index: "/admin/partyHistoryQuestions",
              title: "党史答题",
            },
          ],
        },
        {
          icon: "bi bi-exclamation-triangle",
          index: "6",
          title: "错误处理",
          subs: [
            {
              index: "/admin/NoFind",
              title: "404页面移动端",
            },
            {
              index: "/admin/NotFind",
              title: "404页面PC",
            },
          ],
        },
        
      ],
    };
  },
  computed: {
    onRoutes() {
      this.$route.path.replace("/", "");
      return "1";
    },
    collapse() {
      return this.$store.state.collapse;
    },
  },
};
</script>
<style scoped src="@/assets/Admincss/main.css"></style>
<style lang="less" scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}

.el-menu i {
  margin-right: 5px;
  width: 24px;
  text-align: center;
  font-size: 18px;
  vertical-align: middle;
}
</style>
